package com.mifengs.mall.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mifengs.mall.R;

/**
 * Created by lihaoqi on 2017/3/21.
 */

public class BlankPageView extends RelativeLayout{

    private ImageView ivIcon;
    private TextView tvMsg;
    private Button btnRefreshs;
    private Context context;

    public static final int no_red_packet = 1;

    public static final int no_floor_data = 2;

    public BlankPageView(Context context) {
        super(context);
        init(context);
    }

    public BlankPageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public BlankPageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context){

        LayoutParams rlp=new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        rlp.addRule(RelativeLayout.CENTER_IN_PARENT);//addRule参数对应RelativeLayout XML布局的属性

        this.context = context;
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.public_blank_page,null);

        ViewGroup.LayoutParams lp = v.getLayoutParams();

        ivIcon =  v.findViewById(R.id.ivIcon);
        tvMsg =  v.findViewById(R.id.tvMsg);
        btnRefreshs = v.findViewById(R.id.btnRefreshs);
        this.addView(v,rlp);
    }

    public void setBtnClick(OnClickListener onClickListener){
        btnRefreshs.setOnClickListener(onClickListener);
    }

    public void initViewData(int type){
        switch (type){
            case no_red_packet:
                tvMsg.setText(context.getString(R.string.no_red_packet));
                ivIcon.setImageResource(R.drawable.ic_no_content);
                break;
            case no_floor_data:
                ivIcon.setImageResource(R.drawable.ic_floor_blank_page);
                break;
        }
    }

    public void hidView(){
        this.setVisibility(GONE);
    }
    public void showView(){
        this.setVisibility(VISIBLE);
    }

}
